//
//  BDMallProductPayTableViewCell.m
//  BadBoy
//
//  Created by wen on 2017/7/7.
//  Copyright © 2017年 com.8xiong. All rights reserved.
//

#import "BDMallProductPayTableViewCell.h"
#import "BDMallProductModel.h"
#import "BDHomeModel.h"

@implementation BDMallProductPayTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    style = UITableViewCellStyleValue1;
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
    }
    return self;
}

- (void)configeWithModel:(id)model{
    if ([model isKindOfClass:[BDMallProductModel class]]) {
        BDMallProductModel *productModel = model;
        self.textLabel.text = productModel.title;
        [self.imageView sd_setImageWithURL:[NSURL URLWithString:productModel.cover] placeholderImage:[UIImage imageNamed:@"shop_pic"]];
        self.detailTextLabel.text = [NSString stringWithFormat:@"¥ %@", @(productModel.money)];
    }else if ([model isKindOfClass:[BDHomeModel class]]){
        BDHomeModel *homeModel = model;
        self.textLabel.text = [NSString stringWithFormat:ASLocalizedString(@"%@ 的主题"), homeModel.user.nickname];
        
        NSDictionary *infoPlist = [[NSBundle mainBundle] infoDictionary];
        
        NSString *icon = [[infoPlist valueForKeyPath:@"CFBundleIcons.CFBundlePrimaryIcon.CFBundleIconFiles"] lastObject];
        
        UIImage* image = [UIImage imageNamed:icon];
        [self.imageView sd_setImageWithURL:[NSURL URLWithString:homeModel.cover] placeholderImage:image];
        self.detailTextLabel.text = [NSString stringWithFormat:@"¥ %@", @(homeModel.price)];
    }else if ([model isKindOfClass:[NSDictionary class]]) {
        NSInteger index = [model[@"product_id"] integerValue];
        NSInteger imageIndex = index > 10 ? index - 13 : index;
        self.imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"VIP%@",@(imageIndex)]];
        self.textLabel.text = [NSString stringWithFormat:ASLocalizedString(@"%@ %@天"), model[@"title"], @([model[@"validity"] integerValue] / 3600 / 24)];
        self.detailTextLabel.text = [NSString stringWithFormat:@"¥ %@", model[@"money"]];
    }
}

- (void)layoutSubviews{
    [super layoutSubviews];
    self.imageView.size = CGSizeMake(75, 65);
    self.imageView.left = 10;
    self.imageView.centerY = self.height / 2.0;
    self.imageView.contentMode = UIViewContentModeScaleAspectFit;
    
    self.textLabel.font = [UIFont systemFontOfSize:15];
    self.textLabel.textColor = [UIColor colorWithHexString:@"#101010"];
    [self.textLabel sizeToFit];
    self.textLabel.left = self.imageView.right + 10;
    self.textLabel.top = self.imageView.top + 3;
    
    self.detailTextLabel.font = [UIFont systemFontOfSize:16];
    self.detailTextLabel.textColor = [UIColor colorWithHexString:@"#ff4f00"];
    [self.detailTextLabel sizeToFit];
    self.detailTextLabel.left = self.textLabel.left;
    self.detailTextLabel.bottom = self.imageView.bottom - 3;
}

@end
